#include <iostream>
#include <fstream>
#include <memory>
#include "common.h"


namespace cg
{
   enum turn_t { left_turn = 1, right_turn = -1, colinear = 0 };

   turn_t turn(point_2 const & a, point_2 const & b, point_2 const & c)
   {
      double res = cross(b - a, c - a);

      if (res > 0)
         return left_turn;
      else if (res < 0)
         return right_turn;

      return colinear;
   }

   turn_t turn(segment_2 const & s, point_2 const & p)
   {
      return turn(s.p0, s.p1, p);
   }

   bool has_intersection(segment_2 const & s1, segment_2 const & s2)
   {
      if (!rectangle_2(s1.p0, s1.p1).has_intersection(rectangle_2(s2.p0, s2.p1)))
         return false;

      turn_t t10 = turn(s1, s2.p0);
      turn_t t11 = turn(s1, s2.p1);

      if (t10 == colinear && t11 == colinear)
         return true;

      if ((int)t10 * (int)t11 > 0)
         return false;

      turn_t t20 = turn(s2, s1.p0);
      turn_t t21 = turn(s2, s1.p1);

      if ((int)t20 * (int)t21 > 0)
         return false;
      
      return true;
   }
}

using namespace std;

int seed;

struct TestInput 
{
   virtual int get_int() = 0;
   virtual double get_double() = 0;
   virtual ~TestInput() {};
};

class RandomInput: public TestInput
{
   int seed;

   static const int a = 1664525;
   static const int c = 1013904223;
public:
   RandomInput(int seed) 
      :seed(seed)
   { }

   // return random integer in range 0 .. 2^31-1 
   int get_int() 
   {
      return (seed = seed * a + c) & 0x7fffffff;
   }

   double get_double() 
   {
      const double lo = -1000;
      const double hi = 1000;
      const double scale = 1. / (1 << 30);
      return (lo + (hi - lo) * scale * (get_int() & 0x3fffffff));
   }
};

class StandardInput: public TestInput
{
public:
   int get_int() 
   {
      int res;
      cin >> res;
      return res;
   }

   double get_double() 
   {
      double res;
      cin >> res;
      return res;
   }
};

int main(int argc, char ** argv)
{   
   auto_ptr<TestInput> in(new StandardInput());
   int n = in->get_int();

   int type = in->get_int();

   if (type == 1) {
      int seed = in->get_int();
      in = auto_ptr<TestInput>(new RandomInput(seed));
   }

   int res = 0;
   int p = 1;
   for (int i = 0; i < n; ++i, p *= 239)
   {
      double x1 = in->get_double();
      double y1 = in->get_double();
      double x2 = in->get_double();
      double y2 = in->get_double();
      double x3 = in->get_double();
      double y3 = in->get_double();
      double x4 = in->get_double();
      double y4 = in->get_double();
      if (has_intersection(
               cg::segment_2(
                  cg::point_2(x1, y1),
                  cg::point_2(x2, y2)),
               cg::segment_2(
                  cg::point_2(x3, y3),
                  cg::point_2(x4, y4))))
      {
         res += p;
      } else {
      }

   }
   cout << res << "\n";
   return 0;
}

